using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Services.Protocols;
using System.Web.Services;
using System.Data.SqlClient;
using System.Web.UI.HtmlControls;

//using AjaxControlToolkit;
//using System.Configuration;
public partial class Main_Inventory_OnlineRequestSlip : System.Web.UI.Page
{
    Datautility DU = new Datautility();
    CommonLog Log = new CommonLog();
    RandomNameGenerator randno = new RandomNameGenerator();
    DataTable DTvaluation = new DataTable();
    string OnlineRequest = "";
    string MainOnlineRequest = "";
    string OnlineRequestDetail = "";
    string IP = "";
    int Counter = 3;
    List<string> LstList = new List<string>();
    List<string> LstItemCode = new List<string>();
    List<string> LstItemExtender = new List<string>();
    List<string> LstItemDesc = new List<string>();
    List<string> LstLocationId = new List<string>();
    List<string> LstbinNo = new List<string>();
    List<string> LstAvailQty = new List<string>();
    List<string> LstHiddenReqID = new List<string>();
    List<string> LstQty = new List<string>();
    List<string> LstPeCode = new List<string>();
    List<string> LstPeExtender = new List<string>();
    List<string> LstProductDesc = new List<string>();
    List<string> LstProductModel = new List<string>();
    List<string> LstRo = new List<string>();
    List<string> LstCustomer = new List<string>();
    List<string> LstProjectName = new List<string>();

    [System.Web.Script.Services.ScriptMethod()]
    [System.Web.Services.WebMethod]
    public static List<string> GetItemCode(string prefixText)
    {
        Datautility db = new Datautility();
        DataTable dt = db.getdata("select distinct IVR_ITEM.ITMCODE,IVR_ITem.ITMDESC from IVR_TRAN_ITEM inner join IVR_ITEM on ivr_item.ITMID=IVR_TRAN_ITEM.ITMID where ISNULL(IVR_TRAN_ITEM.ITMQTY,'0') > ISNULL(IVR_TRAN_ITEM.ISSUEQTY,'0') and IVR_ITEM.ITMCODE like  '%" + prefixText + "%' OR IVR_ITEM.ITMDESC like '%" + prefixText + "%'");//from Purchase receveive
        DataTable dtItem = db.getdata("select IVR_ITEM.ITMCODE,IVR_ITEM.ITMDESC from IVR_ITEM inner join IVR_ITEMOPENBAL on IVR_ITEM.ITMID=IVR_ITEMOPENBAL.ITMID  where ISNULL(IVR_ITEMOPENBAL.QUANTITY,'0') >= ISNULL(IVR_ITEMOPENBAL.ISSUEQTY,'0') and IVR_ITEM.ITMCODE like '%" + prefixText + "%' OR IVR_ITEM.ITMDESC like '%" + prefixText + "%'");//from ItemMaster
        dt.Merge(dtItem);
        List<string> ItemCode = new List<string>();
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            ItemCode.Add(Convert.ToString(dt.Rows[i]["ITMDESC"]) + "\\" + dt.Rows[i]["ITMCODE"].ToString());
        }
        return ItemCode;
    }
    [System.Web.Script.Services.ScriptMethod()]
    [System.Web.Services.WebMethod]
    public static List<string> GetPeCode(string prefixText)
    {
        Datautility db = new Datautility();
        DataTable dt = db.getdata("select PecCode from ACC_PRODUCT_MASTER where PecCode like '%" + prefixText + "%'");
        List<string> PeCode = new List<string>();
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            PeCode.Add(Convert.ToString(dt.Rows[i]["PecCode"]));
        }
        return PeCode;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["userid"] == null)
        {
            Response.Redirect("~/SessionExpired.aspx");
        }
        else
        {
            string Pagepermission = "select PAGE_ID,PAGE_ADD,PAGE_VIEW,USERID,USERNAME as EmailID from USER_PERMISSION inner join LOGIN on USER_PERMISSION.USER_ID=LOGIN.USERID where USER_ID='" + Session["userid"].ToString() + "' and PAGE_ID=1029";
            DataTable dt = DU.getdata(Pagepermission);
            if (dt.Rows.Count > 0)
            {
                if (!IsPostBack)
                {
                    if (Request.QueryString["Mode"] == "View")
                    {
                        if (dt.Rows[0]["PAGE_VIEW"].ToString() == "True")
                        {
                            pnlview.Visible = true;
                            pnlonlinedetail.Visible = false;
                            GetDataFromOnlineRequestSlip();
                        }
                        else
                        {
                            Response.Redirect("~/AccessDenied.aspx");
                        }
                    }
                    else
                    {
                        pnlview.Visible = false;
                        pnlonlinedetail.Visible = true;
                        //ddlleasedtype.AutoPostBack = true;
                        BindCustomer(); BindProjectName(); BindUsername();
                        txtreqdate.Text = System.DateTime.Now.ToString("dd/MM/yyyy");
                    }
                    hidemailId.Value = dt.Rows[0]["EmailID"].ToString();
                }
            }
            else
            {
                Response.Redirect("~/AccessDenied.aspx");
            }
        }
    }
    string Body = "";
    protected void MailTextBody(string ItemCode, string ItemDesc, string BinNo, string AvlQty, string ReqQty, string Ro, string Customer, string Project)
    {
        Body += "<tr><td style='border:1px solid #818181; width:15%;'>" + ItemCode + "</td><td style='border:1px solid #818181; width:20%;'>" + ItemDesc + "</td><td style='border:1px solid #818181; text-align:right; width:10%;'>" + BinNo + "</td><td style='border:1px solid #818181; text-align:right; width:5%;'>" + AvlQty + "</td><td style='border:1px solid #818181; text-align:right; width:5%;'>" + ReqQty + "</td><td style='border:1px solid #818181; text-align:right; width:15%;'>" + Ro + "</td><td style='border:1px solid #818181; text-align:right; width:15%;'>" + Customer + "</td><td style='border:1px solid #818181; text-align:right; width:15%;'>" + Project + "</td></tr>";
    }
    protected void SendEMail()
    {
        try
        {
            DataTable DtMail = DU.getdata("Select * from Acc_EmailSetting");
            if (DtMail.Rows.Count > 0)
            {
                Response.Write("E: " + DtMail.Rows.Count.ToString());
                System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
                //mail.To.Add("nprasad@ctdi.com,munna.singh@ctdi.com,vikash.dubay@ctdi.in");
                mail.Bcc.Add("harish@digitalsolutions.co.in");
                mail.From = new System.Net.Mail.MailAddress(hidemailId.Value, DtMail.Rows[1]["MailDisplayName"].ToString().Trim());
                mail.Subject = "Testing Purpose";
                mail.IsBodyHtml = true;
                mail.Body = "<table width='80%' cellpadding='0' cellspacing='0' style='font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: normal'><tr><td>Dear Sir/Madam</td></tr><tr><td>Following Requisition Items are:- </td></tr><tr><td align='center'><table style='border: 1px solid #818181; width: 80%; font-family: Verdana; font-size: 12px;' cellpadding='0' cellspacing='0'><tr><td align='left'>Slip No</td><td align='left'><b>" + txtslipno.Value + "</b></td></tr><tr><td align='left'>Request Date</td><td align='left'>" + txtreqdate.Text + "</td></tr><tr><td align='left'>Requester Name</td><td align='left'><b>" + txtusername.Text + "</b></td></tr><tr><td align='left'>Remarks</td><td align='left'>" + txtremarks.Text + "</td></tr></table></td></tr><tr><td><table style='border: 1px solid #818181; width: 100%; font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: normal;' cellpadding='0' cellspacing='0'><tr style='background-color: #4D8732;'><td colspan='8' style='color: white; border: 1px solid #818181;'><b>Item Detail</b></td></tr><tr><td style='border:1px solid #818181; width:15%;'><b>Item Code</b></td><td style='border:1px solid #818181; width:20%;'><b>Item Desc</b></td><td style='border:1px solid #818181; width:10%;'><b>Bin No</b></td><td style='border:1px solid #818181; width:5%;'><b>Avl Qty</b></td><td style='border:1px solid #818181; width:5%;'><b>Req Qty</b></td><td style='border:1px solid #818181; width:15%;'><b>Ro#</b></td><td style='border:1px solid #818181; width:15%;'><b>Customer</b></td><td style='border:1px solid #818181; width:15%;'><b>Project</b></td></tr>" + Body + "</table></td></tr><tr><td align='right'>&nbsp;</td></tr><tr><td><b>Thanks & Regards</b></td></tr><tr><td><a href='http:\\103.13.97.96/demo/index.aspx' target='_blank'>Link for Login</a>&nbsp;</td></tr></table>";
                System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
                smtp.Host = DtMail.Rows[1]["MailHost"].ToString().Trim();
                smtp.Port = 587;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials = new System.Net.NetworkCredential(DtMail.Rows[1]["MailUserID"].ToString().Trim(), DtMail.Rows[1]["MailPassword"].ToString().Trim());
                smtp.EnableSsl = true;
                smtp.Send(mail);
            }
        }
        catch (Exception ex)
        {
        }
    }
    protected override void LoadViewState(object savedState)
    {
        base.LoadViewState(savedState);
        ViewstateMaintain();
    }
    private void ViewstateMaintain()
    {
        LstList = (List<string>)ViewState["LstList"];
        LstItemCode = (List<string>)ViewState["LstItemCode"];
        LstItemExtender = (List<string>)ViewState["LstItemExtender"];
        LstItemDesc = (List<string>)ViewState["LstItemDesc"];
        LstLocationId = (List<string>)ViewState["LstLocationId"];
        LstbinNo = (List<string>)ViewState["LstbinNo"];
        LstAvailQty = (List<string>)ViewState["LstAvailQty"];
        LstHiddenReqID = (List<string>)ViewState["LstHiddenReqID"];
        LstQty = (List<string>)ViewState["LstQty"];
        LstPeCode = (List<string>)ViewState["LstPeCode"];
        LstPeExtender = (List<string>)ViewState["LstPeExtender"];
        LstProductDesc = (List<string>)ViewState["LstProductDesc"];
        LstProductModel = (List<string>)ViewState["LstProductModel"];
        LstRo = (List<string>)ViewState["LstRo"];
        LstCustomer = (List<string>)ViewState["LstCustomer"];
        LstProjectName = (List<string>)ViewState["LstProjectName"];
        //if (Session["HidCounter"] != null)
        if (LstList != null)
        {
            //int count = Convert.ToInt32(Session["HidCounter"].ToString());
            int count = Convert.ToInt32(LstList.Count.ToString());
            for (int i = 0; i < count; i++)
            {
                Counter++;
                Label lbl = new Label();
                lbl.ID = LstList[i].ToString();
                lbl.Text = Counter.ToString();
                HtmlTableRow htrow = new HtmlTableRow();

                HtmlTableCell htcell1 = new HtmlTableCell();
                TextBox txtitemcode = new TextBox();
                txtitemcode.ID = LstItemCode[i].ToString();
                txtitemcode.Width = Unit.Percentage(96);
                txtitemcode.AutoPostBack = true;
                txtitemcode.CssClass = "input";
                txtitemcode.TextChanged += new EventHandler(txtitemcode_TextChanged);
                htcell1.Controls.Add(txtitemcode);

                AjaxControlToolkit.AutoCompleteExtender ExtenderitemCode = new AjaxControlToolkit.AutoCompleteExtender();
                ExtenderitemCode.ID = LstItemExtender[i].ToString();
                ExtenderitemCode.ServiceMethod = "GetItemCode";
                ExtenderitemCode.MinimumPrefixLength = 1;
                ExtenderitemCode.CompletionInterval = 0;
                ExtenderitemCode.OnClientItemSelected = "duplicaterow";
                ExtenderitemCode.CompletionListCssClass = "AutoExtender";
                ExtenderitemCode.CompletionListItemCssClass = "AutoExtenderList";
                ExtenderitemCode.CompletionListHighlightedItemCssClass = "AutoExtenderHighlight";
                ExtenderitemCode.EnableCaching = false;
                ExtenderitemCode.TargetControlID = txtitemcode.ID;
                htcell1.Controls.Add(ExtenderitemCode);


                HtmlTableCell htcell2 = new HtmlTableCell();
                TextBox txtitemdesc = new TextBox();
                txtitemdesc.ID = LstItemDesc[i].ToString();
                txtitemdesc.Width = Unit.Percentage(96);
                txtitemdesc.Enabled = false;
                txtitemdesc.CssClass = "input";
                txtitemdesc.ForeColor = System.Drawing.Color.Black;
                htcell2.Controls.Add(txtitemdesc);

                HtmlTableCell htcell3 = new HtmlTableCell();
                TextBox txtqty = new TextBox();
                txtqty.ID = LstQty[i].ToString();
                txtqty.Width = Unit.Percentage(96);
                txtqty.CssClass = "inputnumber";
                txtqty.Attributes.Add("onKeyPress", "return isNumberKey(this.id,event)");
                txtqty.Attributes.Add("onblur", "return checkqty(this.id);");
                txtqty.MaxLength = 8;
                htcell3.Controls.Add(txtqty);


                HtmlTableCell htcell4 = new HtmlTableCell();
                TextBox txtpecode = new TextBox();
                txtpecode.ID = LstPeCode[i].ToString();
                txtpecode.Width = Unit.Percentage(96);
                txtpecode.AutoPostBack = true;
                txtpecode.CssClass = "input";
                txtpecode.TextChanged += new EventHandler(txtpecode_TextChanged);
                htcell4.Controls.Add(txtpecode);

                AjaxControlToolkit.AutoCompleteExtender ExternderpeCode = new AjaxControlToolkit.AutoCompleteExtender();
                ExternderpeCode.ID = LstPeExtender[i].ToString();
                ExternderpeCode.ServiceMethod = "GetPeCode";
                ExternderpeCode.MinimumPrefixLength = 1;
                ExternderpeCode.CompletionInterval = 0;
                //ExternderpeCode.OnClientItemSelected = "duplicaterowPe";
                ExternderpeCode.CompletionListCssClass = "AutoExtender";
                ExternderpeCode.CompletionListItemCssClass = "AutoExtenderList";
                ExternderpeCode.CompletionListHighlightedItemCssClass = "AutoExtenderHighlight";
                ExternderpeCode.EnableCaching = false;
                ExternderpeCode.TargetControlID = txtpecode.ID;
                htcell4.Controls.Add(ExternderpeCode);

                HtmlTableCell htcell5 = new HtmlTableCell();
                TextBox txtproductdesc = new TextBox();
                txtproductdesc.ID = LstProductDesc[i].ToString();
                txtproductdesc.Width = Unit.Percentage(96);
                txtproductdesc.ForeColor = System.Drawing.Color.Black;
                txtproductdesc.Enabled = false;
                txtproductdesc.CssClass = "labelText";
                htcell5.Controls.Add(txtproductdesc);


                HtmlTableCell htcell6 = new HtmlTableCell();
                TextBox txtproductmodel = new TextBox();
                txtproductmodel.ID = LstProductModel[i].ToString();
                txtproductmodel.Width = Unit.Percentage(96);
                txtproductmodel.Enabled = false;
                txtproductmodel.CssClass = "labelText";
                txtproductmodel.ForeColor = System.Drawing.Color.Black;
                htcell6.Controls.Add(txtproductmodel);


                HtmlTableCell htcell7 = new HtmlTableCell();
                TextBox txtro = new TextBox();
                txtro.ID = LstRo[i].ToString();
                txtro.Width = Unit.Percentage(96);
                txtro.CssClass = "input";
                htcell7.Controls.Add(txtro);


                HtmlTableCell htcell8 = new HtmlTableCell();
                DropDownList ddlcustomer = new DropDownList();
                ddlcustomer.ID = LstCustomer[i].ToString();
                ddlcustomer.Width = Unit.Percentage(98);
                ddlcustomer.CssClass = "dropdown";
                htcell8.Controls.Add(ddlcustomer);


                HtmlTableCell htcell9 = new HtmlTableCell();
                DropDownList ddlprojectname = new DropDownList();
                ddlprojectname.ID = LstProjectName[i].ToString();
                ddlprojectname.Width = Unit.Percentage(98);
                ddlprojectname.CssClass = "dropdown";
                htcell9.Controls.Add(ddlprojectname);


                HtmlTableCell htcell10 = new HtmlTableCell();
                Label hidTotalqty = new Label();
                hidTotalqty.ID = LstAvailQty[i].ToString();
                hidTotalqty.Width = Unit.Percentage(99);
                hidTotalqty.CssClass = "inputnumber";
                hidTotalqty.Text = "0";
                hidTotalqty.Height = 18;
                hidTotalqty.Style["background-color"] = "LightGray";
                htcell10.Controls.Add(hidTotalqty);

                HiddenField hidTotalReceiveId = new HiddenField();
                hidTotalReceiveId.ID = LstHiddenReqID[i].ToString();
                htcell10.Controls.Add(hidTotalReceiveId);

                HtmlTableCell htcell11 = new HtmlTableCell();
                TextBox txtlocaltionId = new TextBox();
                txtlocaltionId.ID = LstLocationId[i].ToString();
                txtlocaltionId.Width = Unit.Percentage(96);
                txtlocaltionId.Enabled = false;
                txtlocaltionId.CssClass = "labelText";
                txtlocaltionId.ForeColor = System.Drawing.Color.Black;
                htcell11.Controls.Add(txtlocaltionId);

                HtmlTableCell htcell12 = new HtmlTableCell();
                TextBox txtbinNo = new TextBox();
                txtbinNo.ID = LstbinNo[i].ToString();
                txtbinNo.Width = Unit.Percentage(96);
                txtbinNo.Enabled = false;
                txtbinNo.CssClass = "labelText";
                txtbinNo.ForeColor = System.Drawing.Color.Black;
                htcell12.Controls.Add(txtbinNo);

                htrow.Cells.Add(htcell1);
                htrow.Cells.Add(htcell2);
                htrow.Cells.Add(htcell11);
                htrow.Cells.Add(htcell12);
                htrow.Cells.Add(htcell10);
                htrow.Cells.Add(htcell3);
                htrow.Cells.Add(htcell4);
                htrow.Cells.Add(htcell5);
                htrow.Cells.Add(htcell6);
                htrow.Cells.Add(htcell7);
                htrow.Cells.Add(htcell8);
                htrow.Cells.Add(htcell9);

                tblOnlineRequestSlip.Rows.Add(htrow);
            }
        }
    }
    protected void btnAddNew_Click(object sender, EventArgs e)
    {
        Counter++;
        lblrowno.Text = Counter.ToString();
        Label lbl = new Label();
        lbl.ID = "lbl" + Counter.ToString();
        lbl.Text = Counter.ToString();
        LstList.Add(lbl.Text);

        HtmlTableRow htrow = new HtmlTableRow();
        HtmlTableCell htcell1 = new HtmlTableCell();
        TextBox txtitemcode = new TextBox();
        txtitemcode.ID = "txtitemcode" + Counter.ToString();
        txtitemcode.Width = Unit.Percentage(96);
        txtitemcode.AutoPostBack = true;
        txtitemcode.CssClass = "input";
        txtitemcode.TextChanged += new EventHandler(txtitemcode_TextChanged);
        htcell1.Controls.Add(txtitemcode);
        LstItemCode.Add(txtitemcode.ID);

        AjaxControlToolkit.AutoCompleteExtender ExtenderitemCode = new AjaxControlToolkit.AutoCompleteExtender();
        ExtenderitemCode.ID = "ExtenderitemCode" + Counter.ToString();
        ExtenderitemCode.ServiceMethod = "GetItemCode";
        ExtenderitemCode.MinimumPrefixLength = 1;
        ExtenderitemCode.CompletionInterval = 0;
        ExtenderitemCode.OnClientItemSelected = "duplicaterow";
        ExtenderitemCode.CompletionListCssClass = "AutoExtender";
        ExtenderitemCode.CompletionListItemCssClass = "AutoExtenderList";
        ExtenderitemCode.CompletionListHighlightedItemCssClass = "AutoExtenderHighlight";
        ExtenderitemCode.EnableCaching = false;
        ExtenderitemCode.TargetControlID = txtitemcode.ID;
        htcell1.Controls.Add(ExtenderitemCode);
        LstItemExtender.Add(ExtenderitemCode.ID);

        HtmlTableCell htcell2 = new HtmlTableCell();
        TextBox txtitemdesc = new TextBox();
        txtitemdesc.ID = "txtitemdesc" + Counter.ToString();
        txtitemdesc.Width = Unit.Percentage(96);
        txtitemdesc.Enabled = false;
        txtitemdesc.ForeColor = System.Drawing.Color.Black;
        txtitemdesc.CssClass = "labelText";
        htcell2.Controls.Add(txtitemdesc);
        LstItemDesc.Add(txtitemdesc.ID);

        HtmlTableCell htcell3 = new HtmlTableCell();
        TextBox txtqty = new TextBox();
        txtqty.ID = "txtqty" + Counter.ToString();
        txtqty.Width = Unit.Percentage(96);
        txtqty.CssClass = "inputnumber";
        txtqty.Attributes.Add("onKeyPress", "return isNumberKey(this.id,event)");
        txtqty.Attributes.Add("onblur", "return checkqty(this.id);");
        txtqty.MaxLength = 8;
        htcell3.Controls.Add(txtqty);
        LstQty.Add(txtqty.ID);

        HtmlTableCell htcell4 = new HtmlTableCell();
        TextBox txtpecode = new TextBox();
        txtpecode.ID = "txtPecode" + Counter.ToString();
        txtpecode.Width = Unit.Percentage(96);
        txtpecode.AutoPostBack = true;
        txtpecode.CssClass = "input";
        txtpecode.TextChanged += new EventHandler(txtpecode_TextChanged);
        htcell4.Controls.Add(txtpecode);
        LstPeCode.Add(txtpecode.ID);

        AjaxControlToolkit.AutoCompleteExtender ExternderpeCode = new AjaxControlToolkit.AutoCompleteExtender();
        ExternderpeCode.ID = "ExternderpeCode" + Counter.ToString();
        ExternderpeCode.ServiceMethod = "GetPeCode";
        ExternderpeCode.MinimumPrefixLength = 1;
        ExternderpeCode.CompletionInterval = 0;
        //ExternderpeCode.OnClientItemSelected = "duplicaterowPe";
        ExternderpeCode.CompletionListCssClass = "AutoExtender";
        ExternderpeCode.CompletionListItemCssClass = "AutoExtenderList";
        ExternderpeCode.CompletionListHighlightedItemCssClass = "AutoExtenderHighlight";
        ExternderpeCode.EnableCaching = false;
        ExternderpeCode.TargetControlID = txtpecode.ID;
        htcell4.Controls.Add(ExternderpeCode);
        LstPeExtender.Add(ExternderpeCode.ID);

        HtmlTableCell htcell5 = new HtmlTableCell();
        TextBox txtproductdesc = new TextBox();
        txtproductdesc.ID = "txtproductdesc" + Counter.ToString();
        txtproductdesc.Width = Unit.Percentage(96);
        txtproductdesc.Enabled = false;
        txtproductdesc.CssClass = "labelText";
        txtproductdesc.ForeColor = System.Drawing.Color.Black;
        htcell5.Controls.Add(txtproductdesc);
        LstProductDesc.Add(txtproductdesc.ID);

        HtmlTableCell htcell6 = new HtmlTableCell();
        TextBox txtproductmodel = new TextBox();
        txtproductmodel.ID = "txtproductmodel" + Counter.ToString();
        txtproductmodel.Width = Unit.Percentage(96);
        txtproductmodel.Enabled = false;
        txtproductmodel.CssClass = "labelText";
        txtproductmodel.ForeColor = System.Drawing.Color.Black;
        htcell6.Controls.Add(txtproductmodel);
        LstProductModel.Add(txtproductmodel.ID);

        HtmlTableCell htcell7 = new HtmlTableCell();
        TextBox txtro = new TextBox();
        txtro.ID = "txtro" + Counter.ToString();
        txtro.Width = Unit.Percentage(96);
        txtro.CssClass = "input";
        txtro.ForeColor = System.Drawing.Color.Black;
        htcell7.Controls.Add(txtro);
        LstRo.Add(txtro.ID);

        HtmlTableCell htcell8 = new HtmlTableCell();
        DropDownList ddlcustomer = new DropDownList();
        ddlcustomer.ID = "ddlcustomer" + Counter.ToString();
        ddlcustomer.Width = Unit.Percentage(98);
        ddlcustomer.CssClass = "dropdown";
        htcell8.Controls.Add(ddlcustomer);
        LstCustomer.Add(ddlcustomer.ID);

        HtmlTableCell htcell9 = new HtmlTableCell();
        DropDownList ddlprojectname = new DropDownList();
        ddlprojectname.ID = "ddlprojectname" + Counter.ToString();
        ddlprojectname.Width = Unit.Percentage(98);
        ddlprojectname.CssClass = "dropdown";
        htcell9.Controls.Add(ddlprojectname);
        LstProjectName.Add(ddlprojectname.ID);

        HtmlTableCell htcell10 = new HtmlTableCell();
        Label hidTotalqty = new Label();
        hidTotalqty.ID = "hidTotalqty" + Counter.ToString();
        hidTotalqty.Width = Unit.Percentage(99);
        hidTotalqty.Text = "0";
        hidTotalqty.Height = 18;
        hidTotalqty.CssClass = "inputnumber";
        hidTotalqty.Style["background-color"] = "LightGray";
        //hidTotalqty.Attributes.Add("onKeyPress", "return isNumberKey(this.id,event)");
        htcell10.Controls.Add(hidTotalqty);
        LstAvailQty.Add(hidTotalqty.ID);

        HiddenField hidTotalReceiveId = new HiddenField();
        hidTotalReceiveId.ID = "hidTotalReceiveId" + Counter.ToString();
        htcell10.Controls.Add(hidTotalReceiveId);
        LstHiddenReqID.Add(hidTotalReceiveId.ID);

        HtmlTableCell htcell11 = new HtmlTableCell();
        TextBox txtlocaltionId = new TextBox();
        txtlocaltionId.ID = "txtlocaltionId" + Counter.ToString();
        txtlocaltionId.Width = Unit.Percentage(96);
        txtlocaltionId.Enabled = false;
        txtlocaltionId.CssClass = "labelText";
        txtlocaltionId.ForeColor = System.Drawing.Color.Black;
        htcell11.Controls.Add(txtlocaltionId);
        LstLocationId.Add(txtlocaltionId.ID);

        HtmlTableCell htcell12 = new HtmlTableCell();
        TextBox txtbinNo = new TextBox();
        txtbinNo.ID = "txtbinNo" + Counter.ToString();
        txtbinNo.Width = Unit.Percentage(96);
        txtbinNo.Enabled = false;
        txtbinNo.CssClass = "labelText";
        txtbinNo.ForeColor = System.Drawing.Color.Black;
        htcell12.Controls.Add(txtbinNo);
        LstbinNo.Add(txtbinNo.ID);

        htrow.Cells.Add(htcell1);
        htrow.Cells.Add(htcell2);
        htrow.Cells.Add(htcell11);
        htrow.Cells.Add(htcell12);
        htrow.Cells.Add(htcell10);
        htrow.Cells.Add(htcell3);
        htrow.Cells.Add(htcell4);
        htrow.Cells.Add(htcell5);
        htrow.Cells.Add(htcell6);
        htrow.Cells.Add(htcell7);
        htrow.Cells.Add(htcell8);
        htrow.Cells.Add(htcell9);

        tblOnlineRequestSlip.Rows.Add(htrow);

        ViewState["LstList"] = LstList;
        ViewState["LstItemCode"] = LstItemCode;
        ViewState["LstItemExtender"] = LstItemExtender;
        ViewState["LstItemDesc"] = LstItemDesc;
        ViewState["LstLocationId"] = LstLocationId;
        ViewState["LstbinNo"] = LstbinNo;
        ViewState["LstAvailQty"] = LstAvailQty;
        ViewState["LstHiddenReqID"] = LstHiddenReqID;
        ViewState["LstQty"] = LstQty;
        ViewState["LstPeCode"] = LstPeCode;
        ViewState["LstPeExtender"] = LstPeExtender;
        ViewState["LstProductDesc"] = LstProductDesc;
        ViewState["LstProductModel"] = LstProductModel;
        ViewState["LstRo"] = LstRo;
        ViewState["LstCustomer"] = LstCustomer;
        ViewState["LstProjectName"] = LstProjectName;

        idvalue.Value = Counter.ToString();
        //Session["HidCounter"] = Counter.ToString();
        BindCustomer(); BindProjectName();
    }
    protected void BindCustomer()
    {
        string sqlcustomer = "select LM.LNAME,LM.LID from ACC_LEDMAST LM inner join ACC_GRPMAST GM on LM.PGID=GM.GID where GROUPTREEID='002003001006'";
        //string sqlcustomer = "select ACC_LEDMAST.LNAME as LNAME,ACC_LEDMAST.LID as LID  from ACC_LEDMAST inner join ACC_GRPMAST on ACC_LEDMAST.PGID=ACC_GRPMAST.GID and  ACC_GRPMAST.GROUPTREEID LIKE '002003001006%'";
        DataTable dt = DU.getdata(sqlcustomer);
        int count = Convert.ToInt32(idvalue.Value);
        if (dt.Rows.Count > 0)
        {
            DropDownList ddlcust = new DropDownList();
            if (count > 3)
            {
                ddlcust = (DropDownList)tblOnlineRequestSlip.FindControl("ddlcustomer" + count);
                ddlcust.DataSource = dt;
                ddlcust.DataTextField = "LNAME";
                ddlcust.DataValueField = "LID";
                ddlcust.DataBind();
                ddlcust.Items.Insert(0, new ListItem("-Customer-", "0"));
            }
            else
            {
                for (int i = 1; i <= count; i++)
                {
                    ddlcust = (DropDownList)tblOnlineRequestSlip.FindControl("ddlcustomer" + i.ToString());
                    ddlcust.DataSource = dt;
                    ddlcust.DataTextField = "LNAME";
                    ddlcust.DataValueField = "LID";
                    ddlcust.DataBind();
                    ddlcust.Items.Insert(0, new ListItem("-Customer-", "0"));
                }
            }
        }
    }
    protected void BindProjectName()
    {
        string Sqlproject = "SELECT PROJECTID,PROJECTNAME  FROM MAS_PROJECT";
        DataTable dt = DU.getdata(Sqlproject);
        int count = Convert.ToInt32(idvalue.Value);
        if (dt.Rows.Count > 0)
        {
            DropDownList ddlproject = new DropDownList();
            if (count > 3)
            {
                ddlproject = (DropDownList)tblOnlineRequestSlip.FindControl("ddlprojectname" + count);
                ddlproject.DataSource = dt;
                ddlproject.DataTextField = "PROJECTNAME";
                ddlproject.DataValueField = "PROJECTID";
                ddlproject.DataBind();
                ddlproject.Items.Insert(0, new ListItem("-Project-", "0"));
            }
            else
            {
                for (int i = 1; i <= count; i++)
                {
                    ddlproject = (DropDownList)tblOnlineRequestSlip.FindControl("ddlprojectname" + i.ToString());
                    ddlproject.DataSource = dt;
                    ddlproject.DataTextField = "PROJECTNAME";
                    ddlproject.DataValueField = "PROJECTID";
                    ddlproject.DataBind();
                    ddlproject.Items.Insert(0, new ListItem("-Project-", "0"));
                }
            }
        }
    }
    protected void BindUsername()
    {
        string sqlusername = "select (ISNULL(FirstName,'') +' '+ ISNULL(lastName,'')) as USERNAME,UserName as EmailID from Login where UserID='" + Session["userid"].ToString() + "'";
        DataTable dt = DU.getdata(sqlusername);
        if (dt.Rows.Count > 0)
        {
            txtusername.Text = dt.Rows[0]["USERNAME"].ToString();
            hidemailId.Value = dt.Rows[0]["EmailID"].ToString();
            //txtreqdate.Text = System.DateTime.Now.ToShortDateString();            
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (txtreqdate.Text == "")
        {
            txtreqdate.Text = System.DateTime.Now.ToShortDateString();
        }
        try
        {
            if (txtslipno.Value == "")
            {
                #region SaveData
                string strInsertdetail = "";
                string strInsertMain = "";
                //For the Creating the Query.
                strInsertMain = " Exec USP_IVR_SAVE_OnlineRegistrationSlip '" + Convert.ToDateTime(txtreqdate.Text).ToString(string.Format("yyyy/MM/dd")) + "','" + txtusername.Text + "','" + txtremarks.Text + "','0';";
                #endregion
                //for log
                MainOnlineRequest = "RequestDate=" + Convert.ToDateTime(txtreqdate.Text) + ",SlipNo=" + txtslipno.Value + ",UserName" + txtusername.Text + ",Remarks" + txtremarks.Text + ",";
                #region
                int Count = Convert.ToInt32(idvalue.Value);
                for (int i = 1; i <= Count; i++)
                {
                    #region Findcontrol
                    TextBox txtItemCode = (TextBox)tblOnlineRequestSlip.Rows[i - 1].FindControl("txtitemcode" + i.ToString());
                    TextBox txtItemDesc = (TextBox)tblOnlineRequestSlip.Rows[i - 1].FindControl("txtitemdesc" + i.ToString());
                    TextBox txtQty = (TextBox)tblOnlineRequestSlip.Rows[i - 1].FindControl("txtqty" + i.ToString());
                    TextBox txtBinNo = (TextBox)tblOnlineRequestSlip.Rows[i - 1].FindControl("txtbinNo" + i.ToString());
                    TextBox txtPeCode = (TextBox)tblOnlineRequestSlip.Rows[i - 1].FindControl("txtpecode" + i.ToString());
                    TextBox txtProductDesc = (TextBox)tblOnlineRequestSlip.Rows[i - 1].FindControl("txtproductdesc" + i.ToString());
                    TextBox txtProductModel = (TextBox)tblOnlineRequestSlip.Rows[i - 1].FindControl("txtproductmodel" + i.ToString());
                    TextBox txtRo = (TextBox)tblOnlineRequestSlip.Rows[i - 1].FindControl("txtro" + i.ToString());
                    DropDownList ddlCustomer = (DropDownList)tblOnlineRequestSlip.Rows[i - 1].FindControl("ddlcustomer" + i.ToString());
                    DropDownList ddlProjectname = (DropDownList)tblOnlineRequestSlip.Rows[i - 1].FindControl("ddlprojectname" + i.ToString());
                    Label hidTotalqty = (Label)tblOnlineRequestSlip.Rows[i - 1].FindControl("hidTotalqty" + i.ToString());
                    HiddenField hidTotalReceiveId = (HiddenField)tblOnlineRequestSlip.Rows[i - 1].FindControl("hidTotalReceiveId" + i.ToString());
                    string[] Itemcode = txtItemCode.Text.Split('\\');
                    #endregion
                    #region Insert Value in IVR_OnlineregistrationDetail
                    if (txtItemCode.Text != "" || txtQty.Text != "" || txtRo.Text != "" || Convert.ToInt32(ddlCustomer.SelectedValue) > 0 || Convert.ToInt32(ddlProjectname.SelectedValue) > 0)
                    {
                        if (txtQty.Text != "" && txtRo.Text != "" && Convert.ToInt32(ddlCustomer.SelectedValue) > 0 && Convert.ToInt32(ddlProjectname.SelectedValue) > 0)
                        {
                            strInsertdetail += " Exec USP_IVR_SAVE_OnlineRegistration_Detail '" + Itemcode[1] + "','" + txtItemDesc.Text.Trim() + "','" + txtQty.Text.Trim() + "', '" + txtPeCode.Text.Trim() + "', '" + txtProductDesc.Text.Trim() + "', '" + txtProductModel.Text.Trim() + "', '" + txtRo.Text.Trim() + "','" + ddlCustomer.SelectedValue + "','" + ddlProjectname.SelectedValue + "',null,null,null,null,null,null,null,'" + Session["username"].ToString() + "' ;";
                            //For Mail
                            MailTextBody(Itemcode[1], txtItemDesc.Text.Trim(), txtBinNo.Text, hidTotalqty.Text, txtQty.Text, txtRo.Text, ddlCustomer.SelectedItem.Text, ddlProjectname.SelectedItem.Text);
                            //for log
                            OnlineRequestDetail += "ItemCode=" + Itemcode[1] + ",ItemName=" + txtItemDesc.Text + ",RequestQty=" + txtQty.Text + ",RO=" + txtRo.Text + ",Customer=" + ddlCustomer.SelectedItem.Text + ",Project=" + ddlProjectname.SelectedItem.Text + ",";                            
                        }
                        else
                        {

                        }
                    }
                    #endregion
                }
                DataTable Dtslipno = DU.TranGetDataTable(strInsertMain + " " + strInsertdetail);
                txtslipno.Value = Dtslipno.Rows[0]["SLIPNO"].ToString();
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "rowEmpty();", true);
                #endregion
                #region Mail
                SendEMail();
                #endregion
                //For Creating log.
                IP = Request.ServerVariables["REMOTE_ADDR"];
                OnlineRequest = MainOnlineRequest + OnlineRequestDetail;
                Log.SetItemRequest_Issue(Session["userid"].ToString(), Session["username"].ToString(), CommonLog.Type.ActivityLog.ToString(), OnlineRequest, "OnlineRequestSlip.aspx", IP, System.DateTime.Now.ToString());
                ClearControl();
            }
            Response.Redirect("OnlineRequestSlip.aspx?Mode=addnew");            
        }
        catch (Exception ex)
        {
        }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        ClearControl();
    }
    protected void ClearControl()
    {
        txtremarks.Text = "";
        txtreqdate.Text = "";
        int Count = Convert.ToInt32(idvalue.Value);
        for (int i = 1; i <= Count; i++)
        {
            TextBox txtItemCode = (TextBox)tblOnlineRequestSlip.Rows[i - 1].FindControl("txtitemcode" + i.ToString());
            TextBox txtItemDesc = (TextBox)tblOnlineRequestSlip.Rows[i - 1].FindControl("txtitemdesc" + i.ToString());
            TextBox txtQty = (TextBox)tblOnlineRequestSlip.Rows[i - 1].FindControl("txtqty" + i.ToString());
            TextBox txtbinNo = (TextBox)tblOnlineRequestSlip.Rows[i - 1].FindControl("txtbinNo" + i.ToString());
            TextBox txtRo = (TextBox)tblOnlineRequestSlip.Rows[i - 1].FindControl("txtro" + i.ToString());
            Label hidTotalqty = (Label)tblOnlineRequestSlip.Rows[i - 1].FindControl("hidTotalqty" + i.ToString());
            HiddenField hidTotalReceiveId = (HiddenField)tblOnlineRequestSlip.Rows[i - 1].FindControl("hidTotalReceiveId" + i.ToString());
            DropDownList ddlCustomer = (DropDownList)tblOnlineRequestSlip.Rows[i - 1].FindControl("ddlcustomer" + i.ToString());
            DropDownList ddlProjectname = (DropDownList)tblOnlineRequestSlip.Rows[i - 1].FindControl("ddlprojectname" + i.ToString());
            txtItemCode.Text = "";
            txtItemDesc.Text = "";
            txtQty.Text = "";
            txtbinNo.Text = "";
            txtRo.Text = "";
            hidTotalqty.Text = "0";
            hidTotalReceiveId.Value = "";
            ddlCustomer.SelectedValue = "0";
            ddlProjectname.SelectedValue = "0";
        }
    }
    protected void txtitemcode_TextChanged(object sender, EventArgs e)
    {
        TextBox txt = (TextBox)sender;
        string txtid = txt.ID.ToString().Substring(11);
        int rowIndex = Convert.ToInt32(txtid.ToString());
        TextBox txtItemdesc = (TextBox)tblOnlineRequestSlip.Rows[rowIndex - 1].FindControl("txtitemdesc" + rowIndex.ToString());
        TextBox txtLocationId = (TextBox)tblOnlineRequestSlip.Rows[rowIndex - 1].FindControl("txtlocaltionId" + rowIndex.ToString());
        TextBox txtBinNo = (TextBox)tblOnlineRequestSlip.Rows[rowIndex - 1].FindControl("txtbinNo" + rowIndex.ToString());
        TextBox txtItemqty = (TextBox)tblOnlineRequestSlip.Rows[rowIndex - 1].FindControl("txtqty" + rowIndex.ToString());
        Label hidTotalqty = (Label)tblOnlineRequestSlip.Rows[rowIndex - 1].FindControl("hidTotalqty" + rowIndex.ToString());
        HiddenField hidTotalReceiveId = (HiddenField)tblOnlineRequestSlip.Rows[rowIndex - 1].FindControl("hidTotalReceiveId" + rowIndex.ToString());
        if (txt.Text != "")
        {
            string[] tempitemcode = txt.Text.Split('\\');
            string sql = "select IVR_item.ITMID as ITMID,IVR_item.ITMDESC as ITMDESC ,IVR_item.locationId as locationId,IVR_ITEMOTH.BINREF as BINREF from IVR_item inner join IVR_ITEMOTH on IVR_ITEM.ITMID=IVR_ITEMOTH.ITMID where IVR_ITEM.ITMCODE='" + tempitemcode[1] + "'";
            DataTable DT = DU.getdata(sql);
            if (DT.Rows.Count > 0)
            {
                txtItemdesc.Text = DT.Rows[0]["ITMDESC"].ToString();
                txtLocationId.Text = DT.Rows[0]["locationId"].ToString();
                txtBinNo.Text = DT.Rows[0]["BINREF"].ToString();
                string sqlItem = "select TITID,ITMQTY,coalesce(issueqty,0)as ISSUEQTY,BalanceQTY from IVR_TRAN_ITEM inner join IVR_TRAN_MAIN on IVR_TRAN_MAIN.TRNID=ivr_TRAN_ITEM.TRNID  where ITMID='" + DT.Rows[0]["ITMID"].ToString() + "'";
                string sqlOpening = "select SLNUM,ITMID,QUANTITY,ISNULL(BalanceQTY,0) as BalanceQTY from IVR_ITEMOPENBAL where ITMID='" + DT.Rows[0]["ITMID"].ToString() + "'";
                //string sqlItem = "select TITID,ITMQTY,coalesce(issueqty,0)as ISSUEQTY from IVR_TRAN_ITEM where ITMID='" + DT.Rows[0]["ITMID"].ToString() + "' and isnull(ITMQTY,'0') > isnull(issueQTY,'0')";and isnull(BalanceQTY,'0') > 0
                DataTable dtTranItem = DU.getdata(sqlItem);
                DataTable dtopeningstock = DU.getdata(sqlOpening);
                double qty = 0; string TITID = ""; double issueqty = 0;
                if (dtTranItem.Rows.Count > 0 || dtopeningstock.Rows.Count > 0)
                {
                    for (int j = 0; j < dtopeningstock.Rows.Count; j++)
                    {
                        qty = qty + Convert.ToDouble(dtopeningstock.Rows[j]["BalanceQTY"].ToString());
                        TITID += dtopeningstock.Rows[j]["SLNUM"].ToString() + "_";
                    }
                    for (int i = 0; i < dtTranItem.Rows.Count; i++)
                    {
                        //qty = qty + Convert.ToDouble(dtTranItem.Rows[i]["ITMQTY"].ToString());
                        qty = qty + Convert.ToDouble(dtTranItem.Rows[i]["BalanceQTY"].ToString());
                        TITID += "," + dtTranItem.Rows[i]["TITID"].ToString();
                        issueqty = issueqty + Convert.ToDouble(dtTranItem.Rows[i]["ISSUEQTY"].ToString());
                    }
                    //hidTotalqty.Text = (Convert.ToDouble(qty) - Convert.ToDouble(issueqty)).ToString();
                    hidTotalqty.Text = qty.ToString();// - Convert.ToDouble(issueqty)).ToString();
                    //hidTotalReceiveId.Value = TITID.Remove(TITID.Length - 1);
                    hidTotalReceiveId.Value = TITID.ToString();
                    txtItemqty.ToolTip = "Balance Qty (" + string.Format("{0:0.00}", Convert.ToDouble(hidTotalqty.Text)) + ")";
                }
                else
                {
                    //hidTotalqty.Text = (Convert.ToDouble(qty) - Convert.ToDouble(issueqty)).ToString();
                    hidTotalqty.Text = qty.ToString();
                    hidTotalReceiveId.Value = "";
                    txtItemqty.ToolTip = "Balance Qty (" + string.Format("{0:0.00}", Convert.ToDouble(hidTotalqty.Text)) + ")";
                }
            }
            else
            {
                txt.Text = string.Empty;
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "validitemcode();", true);
            }
        }
        else
        {
            txt.Text = string.Empty;
            txtItemdesc.Text = string.Empty;
            txtLocationId.Text = string.Empty;
            txtBinNo.Text = string.Empty;
            hidTotalReceiveId.Value = string.Empty;
            hidTotalqty.Text = string.Empty;
            ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "validitemcode();", true);
        }
    }
    protected void txtpecode_TextChanged(object sender, EventArgs e)
    {
        TextBox txt = (TextBox)sender;
        string txtid = txt.ID.ToString().Substring(9);
        int rowIndex = Convert.ToInt32(txtid.ToString());
        TextBox txtproductdesc = (TextBox)tblOnlineRequestSlip.Rows[rowIndex - 1].FindControl("txtproductdesc" + rowIndex.ToString());
        TextBox txtproductmodel = (TextBox)tblOnlineRequestSlip.Rows[rowIndex - 1].FindControl("txtproductmodel" + rowIndex.ToString());
        if (txt.Text != null)
        {
            string sql = "select ProjectModel, ProjectDesc from ACC_PRODUCT_MASTER where PecCode='" + txt.Text + "'";
            DataTable DT = DU.getdata(sql);
            if (DT.Rows.Count > 0)
            {
                txtproductdesc.Text = DT.Rows[0]["ProjectDesc"].ToString();
                txtproductmodel.Text = DT.Rows[0]["ProjectModel"].ToString();
            }
            else
            {

            }
        }
    }
    protected void GetDataFromOnlineRequestSlip()
    {
        DataTable dt = DU.getdata("USP_IVR_SELECT_ONLINEREQUESTSLIP");
        if (dt.Rows.Count > 0)
        {
            grdonlineregistration.DataSource = dt;
            grdonlineregistration.DataBind();
        }
    }
    protected void grdonlineregistration_DataBound(object sender, EventArgs e)
    {

    }
    protected void grdonlineregistration_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdonlineregistration.PageIndex = e.NewPageIndex;
        GetDataFromOnlineRequestSlip();
    }
    protected void grdonlineregistration_RowEditing(object sender, GridViewEditEventArgs e)
    {

    }
    protected void lnkbtnEdit_Click(object sender, ImageClickEventArgs e)
    {
        ImageButton imgbtn = (ImageButton)sender;
        Response.Redirect("OnlineRequestSlipEdit.aspx?id=" + imgbtn.CommandArgument);
    }
    protected void grdonlineregistration_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lblSlipNo = (Label)e.Row.FindControl("lblSlipNo");
            GridView GrdPOChild = (GridView)e.Row.FindControl("gvPORemarksChild");
            string SqlChildRemarks = "select ORD.itemcode as ITEMCODE,ORD.Itemdesc as ITEMDESC,ORD.RequestQty as REQQTY,ORD.pecode as PECODE,ORD.Productdesc as PRODUCTDESC,ORD.Productmodel as PRODUCTMODEL,ORD.ro as RO,ACC_LEDMAST.LNAME as CUSTOMER,MAS_PROJECT.projectname as PROJECTNAME from ivr_onlineregistration_Detail ORD inner join Ivr_OnlineregistrationSlip ORS on ORD.regid=ORS.regid inner join ACC_LEDMAST on ACC_LEDMAST.LID=ORD.Customer inner join MAS_PROJECT on MAS_PROJECT.projectid=ORD.project Where ORS.slipno='" + lblSlipNo.Text.Trim() + "'";
            DataTable DTOnlineRequest = DU.getdata(SqlChildRemarks);
            DataTable DTChildPO = new DataTable();
            DTChildPO.Columns.Add("ITEMCODE", typeof(string));
            DTChildPO.Columns.Add("ITEMDESC", typeof(string));
            DTChildPO.Columns.Add("QTY", typeof(string));
            DTChildPO.Columns.Add("PECODE", typeof(string));
            DTChildPO.Columns.Add("PRODUCTDESC", typeof(string));
            DTChildPO.Columns.Add("PRODUCTMODEL", typeof(string));
            DTChildPO.Columns.Add("RO", typeof(string));
            DTChildPO.Columns.Add("CUSTOMER", typeof(string));
            DTChildPO.Columns.Add("PROJECTNAME", typeof(string));
            if (DTOnlineRequest.Rows.Count > 0)
            {
                for (int i = 0; i < DTOnlineRequest.Rows.Count; i++)
                {
                    DataRow DR = DTChildPO.NewRow();
                    DR["ITEMCODE"] = DTOnlineRequest.Rows[i]["ITEMCODE"].ToString();
                    DR["ITEMDESC"] = DTOnlineRequest.Rows[i]["ITEMDESC"].ToString();
                    DR["QTY"] = DTOnlineRequest.Rows[i]["REQQTY"].ToString();
                    DR["PECODE"] = DTOnlineRequest.Rows[i]["PECODE"].ToString();
                    DR["PRODUCTDESC"] = DTOnlineRequest.Rows[i]["PRODUCTDESC"].ToString();
                    DR["PRODUCTMODEL"] = DTOnlineRequest.Rows[i]["PRODUCTMODEL"].ToString();
                    DR["RO"] = DTOnlineRequest.Rows[i]["RO"].ToString();
                    DR["CUSTOMER"] = DTOnlineRequest.Rows[i]["CUSTOMER"].ToString();
                    DR["PROJECTNAME"] = DTOnlineRequest.Rows[i]["PROJECTNAME"].ToString();
                    DTChildPO.Rows.Add(DR);
                }
            }
            GrdPOChild.DataSource = DTChildPO;
            GrdPOChild.DataBind();
        }
    }
}